package com.js.basic.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.js.basic.domain.BsExpertFiles;
import com.js.basic.service.IBsExpertFilesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 专家附件Controller
 *
 * @author lzq
 * @date 20240703
 */
@RestController
@RequestMapping("/expertFile")
public class BsExpertFilesController extends BaseController {
    @Autowired
    private IBsExpertFilesService bsExpertFilesService;

    /**
     * 查询专家附件列表
     */
    @RequiresPermissions("basic:expertFile:list")
    @GetMapping("/list")
    public TableDataInfo list(BsExpertFiles bsExpertFiles) {
        startPage();
        List<BsExpertFiles> list = bsExpertFilesService.selectBsExpertFilesList(bsExpertFiles);
        return getDataTable(list);
    }

    /**
     * 导出专家附件列表
     */
    @RequiresPermissions("basic:expertFile:export")
    @Log(title = "专家附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BsExpertFiles bsExpertFiles) {
        List<BsExpertFiles> list = bsExpertFilesService.selectBsExpertFilesList(bsExpertFiles);
        ExcelUtil<BsExpertFiles> util = new ExcelUtil<BsExpertFiles>(BsExpertFiles.class);
        util.exportExcel(response, list, "专家附件数据");
    }

    /**
     * 获取专家附件详细信息
     */
    @RequiresPermissions("basic:expertFile:query")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId) {
        return success(bsExpertFilesService.selectBsExpertFilesByFileId(fileId));
    }

    /**
     * 新增专家附件
     */
    @RequiresPermissions("basic:expertFile:add")
    @Log(title = "专家附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BsExpertFiles bsExpertFiles) {
        return toAjax(bsExpertFilesService.insertBsExpertFiles(bsExpertFiles));
    }

    /**
     * 修改专家附件
     */
    @RequiresPermissions("basic:expertFile:edit")
    @Log(title = "专家附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BsExpertFiles bsExpertFiles) {
        return toAjax(bsExpertFilesService.updateBsExpertFiles(bsExpertFiles));
    }



    @GetMapping("/deleteBsExpertFiles/{name}")
    public AjaxResult deleteFileByFileName(@PathVariable("name") String name) {
        return toAjax(bsExpertFilesService.deleteBsExpertFiles(name));
    }
}
